package com.example.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("*")
                .allowCredentials(true);
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String basePath = System.getProperty("user.dir");
        System.out.println(basePath);
        registry.addResourceHandler("/img/**")
                .addResourceLocations("file:" + basePath + "/img/");


        registry.addResourceHandler("/avatorImages/**")
                .addResourceLocations("file:" + basePath + "/avatorImages/");
        registry.addResourceHandler("/song/**")
                .addResourceLocations("file:" + basePath + "/song/");
    }
}
